package com.xxzb.pack0820;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

//另一种序列化和反序列化的方式
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student implements Externalizable {
    private Integer id;
    private String name;


    @Override
    public void writeExternal(ObjectOutput out) throws IOException {
        System.out.println(this);
        out.writeObject(id);
        out.writeObject(name);
    }

    @Override
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        Object obj1 = in.readObject();
        Object obj2 = in.readObject();
        System.out.println(obj1+"222222");
        System.out.println(obj2+"333333");
    }
}
